package io.github.hadyang.leetcode;

/**
 * @author haoyang.shi
 * @date 2020-02-23
 */
public class BaseSolution {

  protected void swap(int[] nums, int a, int b) {
    int t = nums[a];
    nums[a] = nums[b];
    nums[b] = t;
  }

  protected void printDP(boolean[][] dps) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < dps.length; i++) {
      builder.append("\n").append(i).append(": ");

      for (int j = 0; j < dps[i].length; j++) {
        builder.append(j).append(":").append(dps[i][j]).append("\t");
      }
    }

    System.out.println(builder.toString());
  }

  protected void printDP(int[][] dps) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < dps.length; i++) {
      builder.append("\n").append(i).append(": ");

      for (int j = 0; j < dps[i].length; j++) {
        builder.append(j).append(":").append(dps[i][j]).append("\t");
      }
    }

    System.out.println(builder.toString());
  }

  protected int binarySearch(int[] nums, int start, int end, int target) {
    while (start <= end) {
      int mid = (start + end) >> 1;
      int mid_v = nums[mid];
      if (mid_v == target) return mid;
      else if (mid_v > target) end = mid - 1;
      else start = mid + 1;
    }

    return -1;
  }
}
